package com.atguigu.upp.service;

import com.atguigu.upp.bean.TagInfo;
import com.atguigu.upp.bean.TaskInfo;
import com.atguigu.upp.bean.TaskTagRule;
import com.atguigu.upp.mapper.TagInfoMapper;
import com.atguigu.upp.mapper.TaskInfoMapper;
import com.atguigu.upp.mapper.TaskTagRuleMapper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * Created by Smexy on 2022/10/13
 */
public class MysqlDBService
{

    private TagInfoMapper tagInfoMapper;
    private TaskInfoMapper taskInfoMapper;
    private TaskTagRuleMapper taskTagRuleMapper;

    //在构造器中赋值
    public MysqlDBService(SqlSession sqlSession){
        tagInfoMapper =  sqlSession.getMapper(TagInfoMapper.class);
        taskInfoMapper =  sqlSession.getMapper(TaskInfoMapper.class);
        taskTagRuleMapper =  sqlSession.getMapper(TaskTagRuleMapper.class);
    }

   public TagInfo getTagInfoByTaskId(Integer taskId){

        validTaskId(taskId);

        return tagInfoMapper.getTagInfoByTaskId(taskId);

   }

   public TaskInfo getTaskByTaskId(Integer taskId){

       validTaskId(taskId);

       return taskInfoMapper.getTaskByTaskId(taskId);

   }

   public List<TaskTagRule> getTaskTagRulesByTaskId(Integer taskId){

       validTaskId(taskId);

       return taskTagRuleMapper.getTaskTagRulesByTaskId(taskId);

   }

   public void validTaskId(Integer taskId){
        if (taskId == null || taskId < 0){
            throw  new RuntimeException("taskId 非法!");
        }
   }

    public List<TagInfo> getTagInfoNameEnableToday(){
        return tagInfoMapper.getTagInfoNameEnableToday();
    }
}
